package com.bocai.yuweiwangluo.base;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.event.MainEvent;
import com.bocai.yuweiwangluo.utils.MyProgressUtil;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import de.greenrobot.event.EventBus;


/**
 * Created by Kai on 2015/7/20.
 */
public class BaseFragment extends Fragment implements BaseView {
    private Dialog mDialog;
    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        getActivity().overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getActivity()));
    }

    @Override
    public void showLoading() {
        mDialog = MyProgressUtil.createLoadingDialog(getActivity(),"请稍等...");
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.show();
    }

    @Override
    public void hideLoading() {
        mDialog.dismiss();
    }

    @Override
    public void showError(String msg) {
        Toast.makeText(getActivity(),msg,Toast.LENGTH_SHORT).show();
    }
    @Override
    public void setData(String json) {

    }

    /**
     * 在主线程运行
     * @param event
     */
    public void onEventMainThread(MainEvent event) {
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
